package com.esms.struts.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

import com.esms.bean.Action;
import com.esms.bean.ActionDAO;
import com.esms.bean.Group;
import com.esms.bean.GroupDAO;
import com.esms.struts.action.PersonCreateAction;

public class RoleAssignService {
	
	private static Logger log = Logger.getLogger(RoleAssignService.class);
	
	private RoleAssignService() {}
	public static RoleAssignService $ = new RoleAssignService(); 
	
	public void updateRoles() { 
		//ActionDAO.$.insert(role);
	}
	
	public List getRoles(int roleId) {
		return (List) ActionDAO.$.findById(1);
	}
	
	public List getAllActions() {
		List allActions = ActionDAO.$.findAll();
		List actionNames = new ArrayList();
		for(Iterator it = allActions.iterator(); it.hasNext(); ) {
			Action action = (Action) it.next();
			actionNames.add(action.getActionname());
		}
		log.info(actionNames.toString());
		return actionNames;
	}
	
	public List getSelActions() {
		List selActionList = new ArrayList();
		List list = GroupDAO.$.findByGroupname("��������Ա");
		Group group = list.isEmpty() ? null : (Group) list.get(0);
		if(null == group) 
			return null;
		else {
			Set actionSet = group.getActions();
			for(Iterator it = actionSet.iterator(); it.hasNext(); ) {
				Action action = (Action) it.next();
				selActionList.add(action.getActionname());
			}
			return selActionList;
		}
	}
	
	public List getSelActions(String personType) {
		List selActionList = new ArrayList();
		List list = GroupDAO.$.findByGroupname(personType);
		Group group = list.isEmpty() ? null : (Group) list.get(0);
		if(null == group) 
			return null;
		else {
			Set actionSet = group.getActions();
			for(Iterator it = actionSet.iterator(); it.hasNext(); ) {
				Action action = (Action) it.next();
				selActionList.add(action.getActionname());
			}
			return selActionList;
		}
	}
}
